﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.Data
{
    /// <summary>
    /// BCType的时间段设置类
    /// </summary>
    [Serializable]    
    public class BCDateData:ICloneable
    {
        public BCDateData(int startTime,int endTime,double data = 0)
        {
            this._startTime = startTime;
            this._value = data;
            this._endTime = endTime;
        }

        double _value;
        /// <summary>
        /// 该时间段的值
        /// </summary>
        public double Value
        {
            get { return _value; }
            set { _value = value; }
        }

        int _startTime;
        /// <summary>
        /// 起始时间
        /// </summary>
        public int StartTime
        {
            get { return _startTime; }
            set
            {
                if (_preData == null)
                    _startTime = 1;
                else
                    _startTime = _preData.EndTime + 1;
            }
        }

        int _endTime;
        /// <summary>
        /// 终止时间
        /// </summary>
        public int EndTime
        {
            get { return _endTime; }
            set
            {
                if (_preData != null)
                {
                    if (value <= _preData.EndTime)
                        return;
                }
                if (_afterData != null && value >= _afterData.EndTime)
                    return;
                _endTime = value;
                if (_afterData != null)
                    _afterData.StartTime = value + 1;
            }
        }
        BCDateData _afterData;

        public BCDateData AfterData
        {
            get { return _afterData; }
            set { _afterData = value; }
        }

        BCDateData _preData;

        public BCDateData PreData
        {
            get { return _preData; }
            set { _preData = value; }
        }

        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }
}
